'''
Created on Nov 26, 2011

@author: oabalbin
'''
import numpy as np

def read_ibd_table(file):
    '''
    '''
    ifile=open(file)
    ifile.next()
    records=[]
    ncols=5
    for nrows,l in enumerate(ifile):
        f=l.strip('\chr\n').split('\t')
        if f[0]=='X':
            f[0]=23
        elif f[0]=='Y':
            f[0]=24
        records.append( map(float,f) )
    ibd_table=np.array( records )
    ibd_table=ibd_table[ibd_table[:,2]==1,:]
    ibd_table=ibd_table[ibd_table[:,3]==0,:]
    new_ibd = np.core.records.fromarrays(ibd_table.transpose(),names='CHRM, POS, IBD.OBS, IBD.PRE, MARG',formats = 'int, int, int,int,float')
    new_ibd = np.sort(new_ibd, order=['CHRM', 'POS'])
    
    return ibd_table
    
        
        
file='/exds/users/oabalbin/projects/fmpn/data/gatk_calls/FMPN_63-52-53_ibd2_output.tsv'
read_ibd_table(file)